/**
 * @file es_drv.h
 *
 * @brief Define the drvice description structure and drvice driver interface.
 *
 * @details Open drvice operation interface to the outside world, such as searching for drvices,
 * 		    determining whether the drvice exists, inserting the drvice, and registering the drvice
 *
 * @author bagy
 *
 * @version V1.0
 *
 * @date 2024-05-15
 */

#ifndef  __ES_drv_H__
#define  __ES_drv_H__

#include "elog.h"
#include "es_def.h"
#include "drv_id.h"
#include "es_uart_utils.h"

typedef ES_STRUCT es_drv es_drv_t;

/**
 * @brief drvice driver interface.
 *
 * @details Implement drvice initialization, reading, writing, and control driver.
 */
typedef ES_STRUCT
{
	ES_INT32  (*init) (ES_VOID);
	ES_INT32  (*read) (es_drv_t *drv, ES_VOID *buffer, ES_INT32 size);
	ES_INT32  (*write)(es_drv_t *drv, ES_CONST_VOID *buffer, ES_INT32 size);
	ES_INT32  (*ioctl)(es_drv_t *drv, ES_INT32 cmd, ES_VOID *args);
	ES_VOID   (*isr)  (es_drv_t *drv);

}es_ops_t;

/**
 * @brief Structure used to describe the drvice.
 *
 * @details Store drvice numbers, drvice drivers and other drvice-related parameters.
 */
struct es_drv
{
	ES_INT32                id;
	ES_CONST es_ops_t       *drv_ops;
    ES_VOLATILE ES_VOID     *data;
    ES_U32                  addr;
    ES_U32                  size;
    es_drv_t        		*next;

};

/**
 * @brief Find drvice driver based on drvice descriptor.
 */
extern es_drv_t *es_drv_find(ES_INT32 fd);

/**
 * @brief Determine whether the drvice exists based on the drvice descriptor.
 */
extern bool es_drv_is_exists(ES_INT32 fd);

/**
 * @brief Insert drvice into drvice list.
 */
extern ES_INT32 es_drv_list_inster(es_drv_t *drv);

/**
 * @brief Register drvice.
 */
extern ES_INT32 es_drv_register(es_drv_t *drv);

#endif   /* __ES_drv_H__ */
